<!--<template>
-->
<!--    <div>证据</div>-->
<!--</template>-->
<template>
  <div class="content-center">
    <div class="content-cotainer border-box">
      <div class="content-breadcrumb">
        <el-breadcrumb separator="/" class="breadcrumb">
          <el-breadcrumb-item :to="{ path: '/' }">审计分析</el-breadcrumb-item>
          <el-breadcrumb-item>审计证据</el-breadcrumb-item>
        </el-breadcrumb>
      </div>
      <div class="audit-content">
        <div class="centent-title">
          <span>{{title}}</span>
        </div>
         <el-row :gutter="20" style="margin-top: 20px;padding-left: 2px;">
          <el-form :model="formInline" label-width="130px" size="small">
            <el-row>
              <el-col :span="8">
                <el-form-item label="审计证据名称：">
                  <el-input v-model="formInline.auditPrfNm" placeholder="请输入审计证据名称"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="编制人：">
                  <el-input v-model="formInline.auditItemDsc" placeholder="请选择审计人员" size="small"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="证据状态：">
                  <el-select v-model="formInline.rcrdCrtpsnNm" placeholder="请选择证据状态" size="small">
                    <el-option v-for="item in option" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="16">
                <el-form-item label="审计证据概述：">
                <el-input v-model="formInline.aa" placeholder="请输入审计证据概述" size="small"></el-input>
                </el-form-item>   
              </el-col>
              <el-col :span="7">
                <el-form-item label="附件名称：">
                  <el-input v-model="formInline.bb" placeholder="请输入附件名称" size="small"></el-input>
                  </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="编制日期：">
              <div class="block">
                    <el-date-picker
                      v-model="formInline.createDt"
                      type="daterange"
                      align="right"
                      unlink-panels
                      range-separator="至"
                      start-placeholder="开始日期"
                      end-placeholder="结束日期"
                      :picker-options="pickerOptions">
                    </el-date-picker>
               </div>
                </el-form-item>
              </el-col>
              
              <el-button type="primary" icon="el-icon-search" size="small" style="margin-left:123px;" @click="onSubmit()">查询</el-button>
              <el-button type="primary" icon="el-icon-search" size="small" style="margin-left:12px;" >重置</el-button>
            </el-row>
          </el-form>
        </el-row>
        <div class="centent-inner" style="padding:15px;">
          
          <div>
            <el-button type="primary" size="small" icon="el-icon-document-add" @click="newAdd">新建</el-button>
            <el-button type="primary" size="small" icon="el-icon-share" @click="shareto">共享</el-button>
            <el-button type="danger" size="small" icon="el-icon-delete" @click="deteleEVidence(sels)">废弃</el-button>
            <!-- <el-button type="success" size="small" style="float:right;" icon="el-icon-edit" >修改</el-button> -->
          </div>
          
          <el-table :data="tableData" :row-class-name="tableRowClassName" @selection-change="selsChange" stripe>
            <el-table-column type="selection"></el-table-column>
            <el-table-column type="index" label="序号" width="50" align="center"></el-table-column>
            <el-table-column label="审计证据名称" prop="auditPrfNm" align="center">
              <template slot-scope="scope">
                <el-button type="text" @click="modifyEVidence(scope.row.auditPrfId)">{{scope.row.auditPrfNm}}</el-button>
              </template>
            </el-table-column>
            <el-table-column prop="prfDesc" label="审计证据概述">
              </el-table-column>
              <el-table-column prop="fileName" label="附件名称">
              </el-table-column>
              <el-table-column prop="createDt" label="编制日期"></el-table-column>
              <el-table-column prop="writerNm" label="编制人">
              </el-table-column>
              <el-table-column prop="lcsCd" label="状态"></el-table-column>
              <el-table-column prop="draft" label="已关联审计底稿">
                  <template slot-scope="scope">
                    <el-button type="text" @click="selectDraft()">{{scope.row.draft}}</el-button>
                    </template>
              </el-table-column>
          </el-table>

          <el-dialog :visible.sync="dialogAuditTableVisible" title="审计证据" width="80%" top="10vh">
          <el-table :data="auditTableData"  @selection-change="selsChange" stripe>
            <el-table-column type="selection"></el-table-column>
            <el-table-column type="index" label="序号" width="50" align="center"></el-table-column>
            <el-table-column label="审计证据名称" prop="auditPrfNm" align="center">
            </el-table-column>
            <el-table-column prop="prfDesc" label="审计证据概述">
            </el-table-column>
            <el-table-column prop="fileName" label="附件名称">
            </el-table-column>
            <el-table-column prop="createDt" label="编制日期"></el-table-column>
            <el-table-column prop="writerNm" label="编制人">
            </el-table-column>
            <el-table-column prop="lcsCd" label="状态"></el-table-column>
            <!--<el-table-column prop="draft" label="已关联审计底稿">
              <template slot-scope="scope">
                <el-button type="text" @click="selectDraft()">{{scope.row.draft}}</el-button>
              </template>
            </el-table-column>-->
          </el-table>
          <div slot="footer" class="dialog-footer">
            <el-button @click="dialogAuditTableVisible = false">取消</el-button>
            <el-button  type="primary" @click="relationEvidence()">确定</el-button>
          </div>
        </el-dialog>
        <!-- 共享 -->
          <el-dialog
            title="选择共享的人"
            :visible.sync="dialogVisible" @opened="opened">
            <share :data="data" @cancelshare="cancelshare" @sureshare="sureshare" opened></share>
          </el-dialog>
        </div>
      </div>
    </div>
    
  </div>
</template>

<script>
import axios from "axios"
import share from '@/components/Share'
import evidenceservice from '@/api/auditoperationApi/evidenceservice'
// import {
//   wxLogin
// } from "@/api.js";
export default {
  components: { share },
  data() {
    return {
      dialogAuditTableVisible: false,
      data: [],
      dialogVisible:false,
      tableData: [
      ],
      sels: [],
      auditTableData:[],
       pickerOptions: {
          shortcuts: [{
            text: '最近一周',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit('pick', [start, end]);
            }
          }]
        },
      selectedlist:[], //勾选框
      checked: [],
      formInline: {
        user: '',
        region: ''
      },
      option: [{
        value: '1',
        label: '张三'
      }, {
        value: '2',
        label: '李四'
      }, {
        value: 'zjg',
        label: 'zjg'
      }],
   
      multipleSelection : [],
      total: 3,
      title: '审计证据列表'
    }
  },
  created() {
    // this.wxLogin();
  },
  methods: {
    // 确认分享
    sureshare (data) {
      console.log('确认分享table' + data)
      if (data && data.length > 0) {
        let info = {
        userId:"1001",
        auditGrpId:"10000001",
        auditPrjId:"00000001",
        unknownFileId:"abc12345",
        unknownFileType:"10",
        auditorIds:[]
        }
        data.forEach(item => {
          if (item.checkflag && item.checkflag === true) {
            info.auditorIds.push(
              item.auditorId
            )
          }
        })
        axios.post('http://localhost:7111/fileShare/modifyShareData', info).then((response) => {
          console.log(response)
          if (response && response.success && response.success === true) {
            this.$message.success('分享成功')
          }
        }).catch((response) => {
          console.log(response)
        })
        this.dialogVisible = false
      }
    },
    // 取消分享
    cancelshare () {
      this.dialogVisible = false
    },
    opened() {
      this.getChildVueComponentAttr(this, 'opened')
      this.$emit('opened')
    },
    getChildVueComponentAttr(vm, attr) {
      if (vm == null || attr == null || attr === '') {
        return null
      }
      if (vm.$attrs.hasOwnProperty(attr)) {
        var fn = vm.$attrs[attr]
        if (fn === '') {
          fn = attr
        }
        vm[fn]()
        return vm
      }
      if (vm.$children == null || vm.$children === undefined) {
        return null
      }
      vm.$children.forEach(item => {
        return this.getChildVueComponentAttr(item, attr)
      })
    },
    // 共享
    shareto () {
      this.dialogVisible = true
      // if (this.sels && Array.isArray(this.sels) && this.sels.length > 0) {
      //   this.dialogVisible = true
      // } else {
      //   this.$message.warning('请至少勾选一条需要共享的数据')
      // }
    },
    // 获取列表
    async wxLogin(k = {}) {
      const res = await wxLogin(k);
      console.log(res)
      // if (res.status == 200) {
      //     console.log(res)

      // }
    },
    selsChange(sels) {
      this.sels = sels
    },
    // 查询
    onSubmit() {
      let info = {
        auditPrfNm : this.formInline.auditPrfNm,
        // writerId : this.formInline.writerId,    //编制人
        nodeId :1,
      }
      axios.post('http://128.16.181.100:7111/evidence/queryEvidence', info).then((response) => {
        console.log(response)
        this.tableData = response.data
      }).catch((response) => {
        console.log(response)
      })
    },
    // 修改审计证据
    modifyEVidence(auditPrfId) {
      console.log(this.sels)
      // this.newDraftForm.show = true
      // this.$router.replace({ path: '/auditOperationPage/auditdraftadd/' })
      // if (this.sels && Array.isArray(this.sels) && this.sels.length >=0) {
      //   // 没有勾选行
      //   if (this.sels.length === 0) {
      //     this.$message.warning('请勾选一行数据')
      //   // 勾选一行
      //   } else if (this.sels.length === 1) {
          this.$router.push({
            name: 'auditEvidenceAdd',
            query: {
              type: 'edit',
              id : auditPrfId
            }
          })
        // 勾选多行
      //   } 
      //   // else if (this.sels.length > 1) {
      //   //   this.$message.warning('修改时只能勾选一行')
      //   // }
        
      // }
    },
    //删除
     deteleEVidence(data){
      let ids= this.sels.map(item => item.auditPrfId).join()
      if(ids.length > 0){
        this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
         
          beforeClose: (action, instance, done) => {
            // debugger
            if (action === 'confirm') {
              axios.post('http://128.16.181.100:7111/evidence/deleteEvidence', {ids: ids})
                      .then(response => {
                        this.$message({
                          type: 'success',
                          message: response.data.obj
                          
                        });
                      }, err => {
                      })
                      .catch((error) => {
                      })
            } else {
              done();
            }
          }
        }).then(() => {
          console.log("删除成功")
        })
      }else{
        this.$message({
          type: 'info',
          message: '请选择记录'
        });
      }

    },
    //查询证据关联底稿
    selectDraft(){
        this.dialogAuditTableVisible = true;
      let info = {
        auditDraftNm: this.auditTableData.auditDraftNm,
        auditItemDsc: this.auditTableData.auditItemDsc,
        rcrdCrtpsnNm: this.auditTableData.rcrdCrtpsnNm
      }
      axios.post('http://localhost:7111/auditWorkerDraft/findWorkDraftList', info).then((response) => {
        this.auditTableData = response.data
      }).catch((response) => {
        console.log(response)
      })
    },
    // 多选删除
			// deteleEVidence(data) {
			// 	var _this = this;
			// 	const length = this.multipleSelection.length;
 
			// 	for (let i = 0; i < length; i++) {
			// 		// console.log(this.multipleSelection[i])
			// 		this.deteleEVidence.push(this.multipleSelection[i].id);
			// 		console.log(this.deteleEVidence[i])
			// 	}
			// 	_this.$http({
			// 		method: 'post',
			// 		url: 'http://128.16.181.100:7111/evidence/deleteEvidence?ids=' + this.deteleEVidence,
 
			// 		header: {
			// 			'content-type': 'application/json'
			// 		}
			// 	}).then(function(res) {
			// 		if (res.data.code == 0) {
			// 			alert('成功！');
			// 			_this.getTechSort();
			// 		} else {
			// 			alert('数据加载失败！');
			// 		}
			// 	})
			// },
    //删除审计证据
    // deteleEVidence (tableData) {
    //   console.log(this.selectedlist)
    //   if (this.selectedlist && Array.isArray(this.selectedlist) && this.selectedlist.length >=0) {
    //     // 没有勾选行
    //     if (this.selectedlist.length === 0) {
    //       this.$message.warning('请至少勾选一行')
    //     // 勾选一行或多行
    //     } else if (this.selectedlist.length > 0) {
    //       this.selectedlist.forEach(element => {
    //             this.tableData.splice(element.index, 1, {deleteflag: 1})
    //         })
    //       let templist = []
    //       this.tableData.forEach(item => {
    //         axios.post('http://localhost:7111/evidence/deleteEvidence',item.deleteflag).then((response) => {
    //         console.log(response)
    //         this.tableData = response.data
    //        }).catch((response) => {
    //         console.log(response)
    //       })
    //         // if (!item.deleteflag) {
    //         //   templist.push(item)
    //         // }
    //       })
    //       this.tableData = templist
    //     }

    //   }
    // },
     // 行索引
    tableRowClassName ({ row, rowIndex }) {
      row.index = rowIndex
    },
    selectedchange (val) {
      this.selectedlist = val
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
    },
    newAdd() {
      this.$router.push({
        name: 'auditEvidenceAdd'
      })
    }
   
  },
  mounted() {
			this.onSubmit();
        }
}
</script>

<style lang="less" scoped>
.content-cotainer {
  padding: 0 20px 20px 20px;
  height: 100%;
}
</style>
